/**
 * Progetto PRAISED.
 * 24/gen/2011
 */
package it.uniroma3.engine.model;

import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.commons.lang3.text.StrMatcher;
import org.apache.commons.lang3.text.StrTokenizer;

/**
 * Tokenizer : This class is responsible to split the original text into a list of token with different criteria
 * 
 * @author Accosta Augusto
 * @author Lopez Elisabetta
 *
 */
public class Tokenizer {
	
	/**
	 * This method separates the string text in input into a list of token
	 * The tokens are separated in the input string by single space
	 *  
	 * @param plainText
	 * @return the token list
	 */
	public static List<Token> getTokens(String plainText) {
		StringTokenizer st = new StringTokenizer(plainText);
		List<Token> tokenList = new LinkedList<Token>();
		
		while(st.hasMoreTokens())
			tokenList.add(new Token(st.nextToken(), false));
		
		return tokenList;
	}
	
	/**
	 * This method separates the string text in input into a list of token
	 * The tokens are separated in the input string by a set of characters
	 * 
	 * @param plainText
	 * @return the token list
	 */
	public static List<Token> getTokensByCharSetMatcher(String plainText) {
		StrTokenizer st = new StrTokenizer(plainText, StrMatcher.charSetMatcher(new char[]{'-', '_', '(', ')', ' '}));
		List<Token> tokenList = new LinkedList<Token>();
		List<String> stringList = st.getTokenList();
		
		for (String string : stringList) {
			tokenList.add(new Token(string));
		}
		
		return tokenList;
	}
	
	/**
	 * This method separates the string text in input into a list of string
	 * The string are separated in the input string by a set of characters
	 * 
	 * @param plainText
	 * @return the string list
	 */
	public static List<String> getStringTokensByCharSetMatcher(String plainText) {
		StrTokenizer st = new StrTokenizer(plainText, StrMatcher.charSetMatcher(new char[]{'-', '_', '(', ')', ' '}));
		
		return st.getTokenList();
	}
}
